
#include <BPhysics>
#include <BLabel>
#include <BImage>
#include <BIcon>
#include <BVBoxLayout>
#include <BGridLayout>
#include <BHBoxLayout>
#include <BFileDialog>
#include <BColorDialog>

#include "StringUtils.h"
#include "ObjectPanel.h"

ObjectPanel::ObjectPanel(BWidget* parent) : BGroupBox(parent)
{
	this->setTitle("Object");
	this->setFoldable(true);

	BLabel* nameLabel = new BLabel("Name");
	_nameEdit = new BLineEdit();

	BLabel* enabledLabel = new BLabel("Enabled");
	_enabledCheckBox = new BCheckBox();

	BGridLayout* gridLayout = new BGridLayout(this);
	gridLayout->setWidget(0, 0, nameLabel);
	gridLayout->setWidget(0, 1, _nameEdit);
	gridLayout->setWidget(1, 0, enabledLabel);
	gridLayout->setWidget(1, 1, _enabledCheckBox);
	gridLayout->setSpacing(3);

	connect(this, Signal_AssetChanged, &ObjectPanel::slotAssetChanged);
	connect(_nameEdit, Signal_EditFinished, &ObjectPanel::slotNameEdited);
	connect(_enabledCheckBox, Signal_Toggled, &ObjectPanel::slotEnableToggled);

}
ObjectPanel::~ObjectPanel()
{

}

void ObjectPanel::slotAssetChanged(BObject* object, const BValue& value)
{
	if (BObject* obj = value)
	{
		_nameEdit->setText(obj->name());
		_enabledCheckBox->setChecked(obj->enabled());
	}
}
void ObjectPanel::slotNameEdited(BObject* object, const BValue& value)
{
	const BString& name = value;
	if (BObject* obj = this->asset())
	{
		obj->setName(name);
	}
}
void ObjectPanel::slotEnableToggled(BObject* object, const BValue& value)
{
	bool enabled = value;
	if (BObject* obj = this->asset())
	{
		obj->setEnabled(enabled);
	}
}
